home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / term / term34Source.lha / termBeep.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  2KB  |  91 lines

  1. /*
  2. **    termBeep.c
  3. **
  4. **    Simple beep sound support routine
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Beep():
  13.      *
  14.      *    Produce a simple decent beep sound.
  15.      */
  16.  
  17. VOID
  18. Beep()
  19. {
  20.     struct MsgPort *AudioPort;
  21.  
  22.         /* Create the IO reply port. */
  23.  
  24.     if(AudioPort = (struct MsgPort *)CreateMsgPort())
  25.     {
  26.         struct IOAudio *AudioRequest;
  27.  
  28.             /* Create the audio IO info. */
  29.  
  30.         if(AudioRequest = (struct IOAudio *)CreateIORequest(AudioPort,sizeof(struct IOAudio)))
  31.         {
  32.             STATIC UBYTE AnyChannel[] =
  33.             {
  34.                 LEFT0F,LEFT1F,    RIGHT0F,RIGHT1F
  35.             };
  36.  
  37.             AudioRequest -> ioa_Request . io_Command            = ADCMD_ALLOCATE;
  38.             AudioRequest -> ioa_Request . io_Flags                = ADIOF_NOWAIT | ADIOF_PERVOL;
  39.             AudioRequest -> ioa_Request . io_Message . mn_Node . ln_Pri    = 80;
  40.             AudioRequest -> ioa_Data                    = AnyChannel;
  41.             AudioRequest -> ioa_Length                    = sizeof(AnyChannel);
  42.  
  43.                 /* Open audio.device */
  44.  
  45.             if(!OpenDevice(AUDIONAME,0,AudioRequest,0))
  46.             {
  47.                     /* Minimal sine wave. */
  48.  
  49.                 STATIC BYTE __chip SineWave[] =
  50.                 {
  51.                     90,
  52.                     127,
  53.                     90,
  54.                     0,
  55.                     -90,
  56.                     -127,
  57.                     -90,
  58.                     0
  59.                 };
  60.  
  61.                     /* Prepare to play a beep sound. */
  62.  
  63.                 AudioRequest -> ioa_Request . io_Command    = CMD_WRITE;
  64.                 AudioRequest -> ioa_Request . io_Flags        = ADIOF_PERVOL;
  65.                 AudioRequest -> ioa_Period            = SysBase -> ex_EClockFrequency / 3200;
  66.                 AudioRequest -> ioa_Volume            = 64 / 2;
  67.                 AudioRequest -> ioa_Cycles            = 150;
  68.                 AudioRequest -> ioa_Data            = SineWave;
  69.                 AudioRequest -> ioa_Length            = sizeof(SineWave);
  70.  
  71.                     /* Play it. */
  72.  
  73.                 BeginIO(AudioRequest);
  74.                 WaitIO(AudioRequest);
  75.  
  76.                     /* Close audio.device */
  77.  
  78.                 CloseDevice(AudioRequest);
  79.             }
  80.  
  81.                 /* Free the audio request. */
  82.  
  83.             DeleteIORequest(AudioRequest);
  84.         }
  85.  
  86.             /* Free the IO reply port. */
  87.  
  88.         DeleteMsgPort(AudioPort);
  89.     }
  90. }
  91.